#ifndef	__UNITTEST_H
#define	__UNITTEST_H

/** @file UnitTest.h
 * The definition of class UnitTest
 *
 * @author R.A.Akkersdijk@saxion.nl
 * @version 1.2	2012/09/24
 */

#include <vector>
#include <string>

/// @class UnitTest
/// The generic baseclass for a testset
class UnitTest
{
	protected:
		/// This defines the "TestCase" pseudo-type.
		typedef void (UnitTest::*TestCase)();

	private:
		const std::string   	name;			// The name of this test (for some user feedback)
		std::vector<TestCase>	testcases;		// The set of registered testcases
		bool                    errorExpected;	// The current expect-status
		int		        	    errorCount;		// The current number of errors seen

	protected:
		/// Add a testcase to the testset.
		/// @param testcase		A method from a derived classs that performs a test.
		/// 	@note	To add a testcase to the testset you should say:
		///			@code
		///		addTest( static_cast<TestCase>( &MyTest::myTest1 ) );
		///			@endcode
		void	addTest(TestCase testcase) {
			testcases.push_back(testcase);
		}

		/// Tell the testbase we now expect some error to occur.
		void	expectError()   { errorExpected = true; }

		/// Tell the testcase we expect that no errors will occur.
		void	expectNoError() { errorExpected = false; }


		/// Default version of setUp.
		/// Will be called prior to each testcase
		/// unless overruled by the derived class.
		virtual	void	setUp()	{}

		/// Default version of tearDown.
		/// Will be called after each testcase
		/// unless overruled by the derived class.
		virtual	void	tearDown() {}


		/// Creates an, as yet, empty testset.
		explicit
		UnitTest(const char *name = "UnitTest")
			: name(name), errorExpected(false), errorCount(0)
		{}

		/// Creates an, as yet, empty testset.
		explicit
		UnitTest(const std::string name = "UnitTest")
			: name(name), errorExpected(false), errorCount(0)
		{}

	public:
		/// Runs the test
		/// by invoking all registered testcases.
		/// @return the number of errors seen.
		int	run();

};


#endif	//__UNITTEST_H
// vim:sw=4:ts=4:ai:aw:
